/*
 * @Author: yangluming
 * @Date: 2024-12-16 16:16:34
 * @LastEditors: yangluming
 * @LastEditTime: 2024-12-16 17:17:14
 * @Description: DAO
 */
import 'package:floor/floor.dart';
import 'package:squat_easy/se_db/se_db_entity.dart';

@dao
abstract class VideoDao {
  @Query('SELECT * FROM Video WHERE userId = :userId ORDER BY createTime DESC')
  Future<List<Video>> findVideoByUserId(String userId);

  @insert
  Future<void> insertVideo(Video video);

  @Query('DELETE FROM Video')
  Future<void> deleteAllVideo();
}

@dao
abstract class TrainingDao {
  @Query('SELECT * FROM Training WHERE userId = :userId ORDER BY createTime DESC')
  Future<List<Training>> findTrainingByUserId(String userId);

  @insert
  Future<void> insertTraining(Training training);

  @Query('DELETE FROM Training')
  Future<void> deleteAllTraining();

  @Query('SELECT * FROM Training WHERE userId = :userId ORDER BY createTime DESC LIMIT :limit')
  Future<List<Training>> findLastTrainingByUserId(String userId, int limit);

  @Query('UPDATE Training SET dailyTraining = :dailyTraining WHERE userId = :userId AND createTime = :createTime')
  Future<void> updateTrainingByDateTime(String userId, String createTime, String dailyTraining);
}
